home *** CD-ROM | disk | FTP | other *** search
- {ClassPlug - FreeWare [OdiE -97]. }
-
- unit ClassPlug;
-
- interface
-
- procedure ReplaceParentClass( DClass, OldParent, NewParent: TClass);
-
- implementation
-
- uses
- Windows;
-
- type
- PP = ^Pointer; // Pointer of Pointer of Parent...
-
- procedure ReplaceParentClass( DClass, OldParent, NewParent: TClass);
- var
- a: ^Byte;
- p1,p2: PP;
- prot: Longint;
- begin
- // Simple dummy check..
- if ( NewParent = nil ) or ( DClass = nil ) then Exit;
-
- // Find the class Parent pointer of AClass
- while ( DClass.ClassParent <> OldParent ) do begin
- if DClass.ClassParent = nil then Exit;
- if DClass.ClassParent = NewParent then Exit;
- DClass := DClass.ClassParent;
- end;
-
- a := Pointer(DClass);
- inc(a,vmtParent);
- p1 := Pointer(a);
-
- // Find the class Self pointer of NewParent, wich will be used to
- // fill the place of the ParentClass Pointer...
- // (this is also quite basic...)
- a := Pointer(NewParent);
- inc(a,vmtSelfPtr);
- p2 := Pointer(a);
-
- // Big THANX to Cyril Jandia for the next 3 steps...
- // Taken from the DMZ #24 class traps example...
- // I had it all worked out, except for the VirtualProtect thingy..
-
- VirtualProtect(p1, SizeOf(Pointer), PAGE_READWRITE, @prot); // let's be brave
- p1^ := p2; // let's be yet more brave
- // time to be clean: not necessary but easy to do, then...
- VirtualProtect(P1, SizeOf(Pointer), prot, @prot);
-
- // use the next line to visualize the change...
- // TClass(PP(P1)^^).className
- end;
-
- end.
-
-